home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / POINTERS.SWG / 0001_DLLIST1.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  960b  |  55 lines

  1. { > Does anybody have any good source/Units For Turbo
  2.  > Pascal 6.0/7.0 For doing Double Linked List File
  3.  > structures?
  4. }
  5.  
  6. Type
  7.  
  8.    DLinkPtr = ^DLinkRecord;
  9.  
  10.    DLinkRecord = Record
  11.       Data     : Integer;
  12.       Next     : DLinkPtr;
  13.       Last     : DLinkPtr;
  14.      end;
  15.  
  16. Var
  17.   Current,
  18.   First,
  19.   Final,
  20.   Prev    : DLinkPtr;
  21.   X       : Byte;
  22.  
  23. Procedure AddNode;
  24. begin
  25.   if First = Nil then
  26.    begin
  27.      New(Current);
  28.      Current^.Next:=Nil;
  29.      Current^.Last:=Nil;
  30.      Current^.Data:=32;
  31.      First:=Current;
  32.      Final:=Current;
  33.    end
  34.   else
  35.    begin
  36.     Prev:=Current;
  37.     New(Current);
  38.     Current^.Next:=Nil;
  39.     Current^.Last:=Prev;
  40.     Current^.Data:=54;
  41.     Prev^.Next:=Current;
  42.     Final:=Current;
  43.    end;
  44. end;
  45.  
  46. begin
  47.   First:=Nil;
  48.   For X:=1 to 10 Do AddNode;
  49.   Writeln('First: ',first^.data);
  50.   Writeln('Final: ',final^.data);
  51.   Writeln('Others:');
  52.   Writeln(first^.next^.data);
  53.  
  54. end.
  55.